#!/usr/bin/perl
#Purpose
#This will grab media info and dump it to a txt file for php to import into sql .. perl + sql == super slut .. php + sql = less slutty 
use File::Basename;
use URI::file;
$output = "/home/wylde/media.dump";
$mediaPath = "/MediaPool/";
#Will need to be editted for all file types 
chomp(@files = `find $mediaPath -type f -name "*.avi" -o -name "*.mkv" -o -name "*.mp4" -o -name "*.mpeg" -o -name "*.wmv" -o -name "*.mpg" -o -name "*.bin" -o -name "*.iso" -o -name "*.asf" -o -name "*.img" -o -name "*.mp2" -o -name "*.ts" -o -name "*.mp3" -o -name "*.flac"`);
open OUTPUT, ">$output" or die "cant open $output for writing\n";
#Need -> Type, Category, Filename, Title
$blah = @files; 
print $blah;
for ($x=0; $x<@files; $x++ ) 
{
	$file = $files[$x]; 
	@raw = split('\/', $file);
	$count = @raw;
	shift(@raw); # Removes blank element	
	shift(@raw); # Removes $mediaPath we have this elsewhere
	$type = $raw[0];
	shift(@raw); # drops Type
	$category = $raw[0];
	shift(@raw); # drops Category
	$title = $raw[0];
	$filename = join('/', @raw);
	$URIfilename = URI::file->new( $filename);
#	$URIfilename =~ s/]/\\]/;
#	$URIfilename =~ s/\[/\\[/;
	#$URIfilename = URI::file->new( $filename);
#debug VERY verbose	print "$file\nType -> $type\nCategory -> $category\nTitle -> $title\nFilename -> $filename\n";	
	print OUTPUT "$type,,,,,$category,,,,,$title,,,,,$filename\n";
	print "--------------------------------------\n";
}


close(OUTPUT);
